package cn.lingyangwl.agile.pay.mch.controller;

import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.agile.pay.model.rqrs.PayIfDefineQL;
import cn.lingyangwl.agile.pay.model.rqrs.PayInterfaceDefineRQ;
import cn.lingyangwl.agile.pay.model.entity.PayInterfaceDefine;
import cn.lingyangwl.agile.pay.common.service.PayInterfaceDefineService;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.framework.security.xss.core.XssCleanIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shenguangyang
 */
@Slf4j
@RestController
@RequestMapping("/mgr/payIfDefine")
public class PayInterfaceDefineController {
    @Resource
    private PayInterfaceDefineService payInterfaceDefineService;

    @RamResource(action = "pay:payInterfaceDefine:list", name = "查询支付接口定义列表", type = ActionType.READ)
    @GetMapping("/listPayIfDefine")
    public Resp<List<PayInterfaceDefine>> listPayIfDefine(PayIfDefineQL query) {
        List<PayInterfaceDefine> resp = payInterfaceDefineService.listPayIfDefine(query);
        return Resp.ok(resp);
    }

    /**
     * 分页查询接口定义
     */
    @RamResource(action = "pay:payInterfaceDefine:list", name = "查询支付接口定义列表", type = ActionType.READ)
    @GetMapping("/page")
    public Resp<IPage<PayInterfaceDefine>> page(PayIfDefineQL query) {
        IPage<PayInterfaceDefine> resp = payInterfaceDefineService.pagePayIfDefine(query);
        return Resp.ok(resp);
    }

    /**
     * 保存操作
     */
    @PostMapping("/save")
    @XssCleanIgnore({"normalMchParams", "isvsubMchParams"})
    @RamResource(action = "pay:payInterfaceDefine:save", name = "保存支付接口定义", type = ActionType.WRITE)
    public Resp<?> save(@RequestBody PayInterfaceDefineRQ req) {
        payInterfaceDefineService.savePayIfDefine(req);
        return Resp.ok();
    }

    /**
     * 通过接口代码获取接口定义
     */
    @GetMapping("/getByIfCode")
    @RamResource(action = "pay:payInterfaceDefine:get", name = "查询支付接口定义详情", type = ActionType.READ)
    public Resp<PayInterfaceDefine> getByIfCode(@RequestParam("ifCode") String ifCode) {
        PayInterfaceDefine resp = payInterfaceDefineService.getByIfCode(ifCode);
        return Resp.ok(resp);
    }

    /**
     * 更新操作
     */
    @PostMapping("/update")
    @XssCleanIgnore({"normalMchParams", "isvsubMchParams"})
    @RamResource(action = "pay:payInterfaceDefine:update", name = "更新支付接口定义", type = ActionType.WRITE)
    public Resp<?> update(@RequestBody PayInterfaceDefineRQ req) {
        payInterfaceDefineService.updatePayIfDefine(req);
        return Resp.ok();
    }

    /**
     * 删除操作
     */
    @DeleteMapping("/delete")
    @RamResource(action = "pay:payInterfaceDefine:delete", name = "删除支付接口定义", type = ActionType.WRITE)
    public Resp<?> delete(@RequestParam("id") Long id) {
        payInterfaceDefineService.deletePayIfDefine(id);
        return Resp.ok();
    }
}
